<template>
	<view class="content">
		
		
		<view class="index_to">
			返回首页
		</view>

		<view class="topss">
			<view>
				代理号:
			</view>
			<view>
				{{code}}
			</view>

		</view>

		<view class='lists' v-for="itees in datas" :key='itees.name'>
			<div class='no_main' @click='gethref(itees)'>
				<span>
					<div style='border-radius: 10px; height: 80px; width: 80px; overflow: hidden;'>
						<image :src="itees.img1[0]"
							style="width: 80px; height: 80px;border-radius: 10px; overflow: hidden;">
						</image>
					</div>
				</span>
				<span>
					<span class="xinxi">
						<p style="	font-size: 18px;font-weight :600;">{{itees.name}}</p>
						<p style="margin: 5px 0 5px 0;">{{shouquan}}</p>
						<p>{{itees.adds}}</p>
					</span>
				</span>
				<span style='font-size: 12px; color: #F0AD4E;'>{{itees.juli}}</span>
			</div>
			<div>
				<div class='ssd'>
					<span @click='openMap(itees.jingdu,itees.weidu)'>立即导航</span>
					<span @click="goPhoneBtn(itees.dianhuahao)">联系商家</span>
					<span @tap="gethref(itees)">查看详情</span>
				</div>
			</div>
		</view>



	</view>
</template>

<script>
	import amap from '../../common/amap-wx.130.js'
	export default {
		data() {
			return {
				amapPlugin: null,
				shouquan: '授权店',
				code: '121215454',
				jindu: '',
				weidu: '',
				datalist: {
					phone: '18796301100',
					page: 1,
				},
				key: '31594b13defecdf492a8668f763bc187',

				dataimgd: {

				},
				datas: [

				]
			}
		},
		onLoad() {
			this.amapPlugin = new amap.AMapWX({
				key: this.key
			})
			this.getRegeo()
			this.loglist()
		},
		onShow() {
			let _this = this
			uni.getStorage({
				key: 'daili_key',
				success: function(res) {

					_this.datalist.phone = res.data.data.mobile
					_this.code = res.data.data.code
					console.log("**************");
					console.log(_this.datalist);
					console.log("**************");
				}
			});
			this.loglist()
		},
		
		onUnload() {
			//#ifdef MP-WEIXIN
			wx.reLaunch({
				url: '../../index/index'
			})
			//#endif
		},
		
		onBackPress(options) {
			if (options.from === 'backbutton') {
				if (this.editShow.edit) {
					uni.showModal({
						title: '提示',
						content: '回执信息未保存，是否离开',
						success: res => {
							if (res.confirm) {
								uni.navigateBack();
							}
						}
					});
					// 禁止默认返回
					return true;
				}
			}
		},
		
		
		
		methods: {




			getRegeo() {
				const _this = this;
				let htp = this.$http
				wx.getSetting({
					success(res) {
						const writePhotosAlbum = res.authSetting['scope.userLocation']
						if (!writePhotosAlbum) { //检查用户是否授权
							openSetting()
						} else {
							console.log("用户拒绝授权");
							uni.hideLoading();
							console.log("sssss");
						}
					}
				})
				const openSetting = () => {
					wx.openSetting({
						success(res) {
							_this.amapPlugin.getRegeo({
								success: (data) => {
									console.log(data, '当前定位')
									_this.addressName = data[0].regeocodeData.addressComponent
										.city + data[0].regeocodeData
										.addressComponent.district
									_this.jindu = data[0].longitude
									_this.weidu = data[0].latitude
									_this.datalist.jingdu = data[0].longitude
									_this.datalist.weidu = data[0].latitude
									// 正常请求不传参数
									setTimeout(() => {
										uni.showLoading({
											title: '获取信息中'
										});
										htp.getData(_this.datalist)
											.then(res => {
												_this.datas = res.data
												console.log("获取的数据");
												// "["http:\/\/xie.sdjunchen.com\/upload\/4d\/23e4f88293b28f85517c4057cd8403.jpg","htt]"
												console.log(res)
												uni.hideLoading();
											})
									}, 2000);

								},
								file: (err) => {
									console.log(err)
								},
							});
							console.log(res)
							uni.hideLoading();
						}
					})
				}

				_this.amapPlugin.getRegeo({
					success: (data) => {
						console.log(data, '当前定位')
						_this.addressName = data[0].regeocodeData.addressComponent.city + data[0].regeocodeData
							.addressComponent.district
						_this.jindu = data[0].longitude
						_this.weidu = data[0].latitude
						_this.datalist.jingdu = data[0].longitude
						_this.datalist.weidu = data[0].latitude
						this.loglist()
					},
					file: (err) => {
						console.log(err)
					},
				});
			},

			// http://xie.sdjunchen.com/index/api.index/list
			loglist() {
				// 正常请求不传参数
				setTimeout(() => {
					uni.showLoading({
						title: '获取信息中'
					});
					this.$http.elpostroot(this.datalist)
						.then(res => {
							this.datas = res.data
							console.log("获取的数据");
							// "["http:\/\/xie.sdjunchen.com\/upload\/4d\/23e4f88293b28f85517c4057cd8403.jpg","htt]"
							console.log(res)
							uni.hideLoading();
						})
				}, 2000);

			},





			//调用手机拨号
			goPhoneBtn(val) {
				uni.makePhoneCall({
					// 手机号
					phoneNumber: val,
					// 成功回调
					success: (res) => {
						console.log(res);
					},
					// 失败回调
					fail: (res) => {
						console.log(res);
					}
				});
			},






			a() {

			},
			//跳转详情
			gethref(ids) {
				var item = JSON.stringify(ids);
				uni.navigateTo({
					url: '../xinagqingye/xiangqingye?item=' + item,
					// pages/index/pages/xinagqingye/xiangqingye
					fail: (res) => {
						console.log(res) //打印错误信息
					}
				});
				console.log('您掉的');
			},


			//导航
			openMap(lon, lat) {
				console.log("获取经纬度ssssfff", lon, lat);

				uni.getLocation({
					success: res => {
						// res.latitude=lat;
						// res.longitude=lon;
						console.log('location success', parseFloat(lat), parseFloat(lon))
						uni.openLocation({
							latitude: parseFloat(lat),
							longitude: parseFloat(lon),
							scale: 18
						})
					}
				})
			},


		}
	}
</script>

<style>
	.topss {
		display: flex;
		background-color: #FFFFFF;
		padding: 10px 0 10px 10px;
	}

	.topss>view:nth-child(1) {
		font-weight: 600;
	}

	.topss>view:nth-child(2) {
		color: red;
	}

	.ssd>span {
		line-height: 300%;
	}

	.content {
		background-color: #f3f1f4;
		height: 100%;
		overflow-x: hidden;
		position: relative;
	}
	
	.content .index_to{
		position: absolute;
		bottom: 50px;
		right: 45px;
		background-color: #000000;
		width: 40px;
		height: 4
		0px;
		border-radius: 25%;
		color: #feff9e;
	}

	.content>view {
		margin-bottom: 10px;
	}

	.dingwei {
		width: 100%;
		display: flex;
		justify-content: space-around;
		background-color: #fff;
		padding: 10px;
	}

	.dingwei image {
		max-width: 40px;
		max-height: 40px;
	}

	.dinweisize {
		display: flex;
		justify-content: center;
	}

	.dinweisize p:nth-child(1) {
		font-size: 14px;
		margin: 0px;
		padding-bottom: 5px;
		margin-left: 10px;
	}

	.dinweisize p:nth-child(2) {
		margin-left: 10px;
		font-size: 12px;
		color: #606266;
	}

	.chongxin {
		display: flex;
		justify-content: center;
		flex-direction: column;
		font-size: 12px;
		min-width: 70px;
	}


	.imgs {
		max-width: 40px;
		max-height: 40px;
		border-radius: 50%;
		overflow: hidden;
		background-color: #eeeeb2;
	}

	.u-page {
		width: 100%;
		background-color: #fff;
	}

	.logs {
		display: block;
		text-align: center;
		color: #fff;
		background-color: #00557f;
		margin-bottom: 10px;
	}

	.logs>image {
		height: 100px;
		width: 100%;
		background-size: cover;
		object-fit: fill
	}
</style>


<style scoped>
	.lists {
		background-color: #19BE6B;
		display: flex;
		width: 100%;
		height: 10rem;
		display: flex;
		justify-content: center;
		flex-direction: column;
	}

	.lists>div {
		width: 100%;
		background-color: #fff;
	}

	.lists>div:nth-child(1) {
		height: 70%;
	}

	.lists>div:nth-child(2) {
		height: 30%;
		border-top: 1px solid #ececec;
		display: flex;
		justify-content: center;
		flex-direction: column;
	}

	.lists>div:nth-child(2)>div {
		display: flex;
		justify-content: space-around;
	}

	.lists>div:nth-child(2)>div>span {
		color: #000;
		font-size: 13px;
	}

	.lists>div:nth-child(2)>div>span:nth-child(1) {
		padding-left: 20px;
	}

	/* DADBDE */
	.lists>div:nth-child(2)>div>span:nth-child(2) {
		border-left: 1px solid #DADBDE;
		border-right: 1px solid #DADBDE;
		padding: 0 50px 0 50px;
	}

	.lists>div:nth-child(2)>div>span:nth-child(3) {
		padding-right: 20px;
	}

	.no_main {
		display: flex;
		justify-content: space-between;
	}

	.no_main>span {
		width: 100%;
		display: flex;
		justify-content: center;
		flex-direction: column;
	}

	.no_main>span:nth-child(1) {

		text-align: center;
		width: 22%;
		padding-left: 20px;
	}

	.no_main>span:nth-child(2) {
		width: 56%;
		margin: 10px;
		display: flex;
		flex-direction: column;
	}



	.xinxi>p:nth-child(2) {
		color: #6e3002;
		width: 50px;
		background-color: #eac788;
		font-size: 12px;
		text-align: center;
		border-radius: 20px;
	}

	.xinxi {
		width: 164px;
	}

	.xinxi>p:nth-child(3) {
		font-size: 12px;
		color: #8f8f8f;
	}

	.no_main>span:nth-child(3) {

		text-align: center;
		width: 22%;
		padding-right: 20px;
	}
</style>
